package com.want.config;

import com.want.client.Client;
import com.want.client.WantLoadBalanceClient;
import com.want.client.instance.list.ServiceInstanceListService;
import com.want.client.instance.list.impl.DefaultServiceInstanceListService;
import com.want.client.loadbanlance.LoadBalanceSelect;
import com.want.client.loadbanlance.impl.RoundLoadBalanceSelect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;

/**
 * @author WangZhiJian
 * @since 2021/12/19 0019
 */
@EnableDiscoveryClient
public class DefaultClientConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public ServiceInstanceListService serviceInstanceListService(){
        return new DefaultServiceInstanceListService();
    }

    @Bean
    @ConditionalOnMissingBean
    public LoadBalanceSelect loadBalanceSelect(){
        return new RoundLoadBalanceSelect();
    }

    @Bean
    @ConditionalOnMissingBean
    public Client defaultClient(ServiceInstanceListService serviceInstanceListService,LoadBalanceSelect loadBalanceSelect){
        return new WantLoadBalanceClient(new Client.DefaultClient(),null,loadBalanceSelect,serviceInstanceListService);
    }
}
